<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<html>
<head>
	<title>产品管理</title>
	<meta name="decorator" content="default"/>
	<script type="text/javascript">
		$(document).ready(function() {
			$('#category_id').val('${search.category}-${search.pic6}');
			
			changeCategory('${search.category}-${search.pic6}');
			
		});
		function page(n,s){
			$("#pageNo").val(n);
			$("#pageSize").val(s);
			$("#searchForm").submit();
        	return false;
        }
		
		function changeCategory(parentId){
			var pid = parentId.split('-');
			parentId = pid[1];
			$('#category_v').val(pid[0]);
			$.post('${ctx}/wechat/productCategory/child/?id='+parentId,function(data){
				var str = "<option value='0' selected='selected'>请选择</option>";
				$.each(data,function(i,item){
					var strselect = "";
					 if(item.value == '${search.subCategory}'){
						 strselect = "selected='selected'";
					 }
					 str+="<option value='"+item.value+"' "+ strselect +">"+item.name+"</option>" ; 
				});
				
				$('#subcategory_id').html(str);
			},'json');
			
		}
		
		function beforeSubmit(){
			var pid = $('#category_id').val();
			var  pv = pid.split('-');
			  parentId = pv[0];
			$('#category_v').val(parentId);
			$('#pic6').val(pv[1]);
			searchForm.submit();
			//return true;
		}
		
	</script>
</head>
<body>
	<ul class="nav nav-tabs">
		<li  ><a href="${ctx}/wechat/productCategory/">类别管理</a></li>
		<li class="active"><a href="${ctx}/wechat/product/">产品列表</a></li>
		<shiro:hasPermission name="wechat:product:edit"><li><a href="${ctx}/wechat/product/form">产品添加</a></li></shiro:hasPermission>
	</ul>
	<form:form id="searchForm" modelAttribute="product" action="${ctx}/wechat/product/" method="post" class="breadcrumb form-search">
		<input id="pageNo" name="pageNo" type="hidden" value="${page.pageNo}"/>
		<input id="pageSize" name="pageSize" type="hidden" value="${page.pageSize}"/>
		<input id="category_v" name="category" type="hidden" value="${category }"/>
		<input id="pic6" name="pic6" type="hidden" value="${pic6}"/>
		<label>名称 ：</label><form:input path="name" htmlEscape="false" maxlength="50" class="input-medium"/>
		<label>主类别 ：</label>
		<select name="categoryList" id="category_id" onchange="changeCategory(this.value)">
					<c:forEach items="${categoryList }" var="category" >
						<option value="${category.value}-${category.id}"  <c:if test="${productCategory.parent.id eq category.id} ">selected</c:if> >${category.name }</option>
					</c:forEach>
		</select>
		<label>子类别 ：</label>
		<form:select path="subCategory" id="subcategory_id" >
			<form:option value="0">请选择</form:option>
		</form:select>
		&nbsp;<input id="btnSubmit" class="btn btn-primary" type="button" onclick="beforeSubmit();" value="查询"/>
	</form:form>
	<tags:message content="${message}"/>
	<table id="contentTable" class="table table-striped table-bordered ">
		<thead><tr><th>名称</th><th>价格</th><th>简介</th><th>是否发布</th><shiro:hasPermission name="wechat:product:edit"><th>操作</th></shiro:hasPermission></tr></thead>
		<tbody>
		<c:forEach items="${page.list}" var="product">
			<tr>
				<td><a href="${ctx}/wechat/product/form?id=${product.id}">${product.name}</a></td>
				<td>${product.price}</td>
				<td>${product.description}</td>
				<td>${product.isSale}</td>
				<shiro:hasPermission name="wechat:product:edit"><td nowrap="nowrap">
    				<a id="a_update_${product.id }" href="${ctx}/wechat/product/form?id=${product.id}" class="btn btn-primary">修改</a>
    				<a href="${ctx}/wechat/product/sort?id=${product.id}&sort=1" class="btn btn-warning">上移</a>
    				<a href="${ctx}/wechat/product/sort?id=${product.id}&sort=-1" class="btn btn-warning">下移</a>
					<a href="${ctx}/wechat/product/delete?id=${product.id}" onclick="return confirmx('确认要删除该产品吗？', this.href)"  class="btn btn-danger">删除</a>
				</td></shiro:hasPermission>
			</tr>
		</c:forEach>
		</tbody>
	</table>
	<div class="pagination">${page}</div>
</body>
</html>
